package mysql

import (
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Phone_num   string `gorm:"type:varchar(50);comment:手机号"`
	Password    string `gorm:"type:varchar(50);comment:密码"`
	Avatar_link string `gorm:"type:varchar(500);comment:头像"`
	Nick_name   string `gorm:"type:varchar(50);comment:昵称"`
}

func (u *User) FindUserByPhoneNum(db *gorm.DB, phone_num string) error {
	return db.Where("phone_num = ?", phone_num).FirstOrCreate(u).Error
}

func (u *User) FindUserByLogin(db *gorm.DB, phone_num string) error {
	return db.Where("phone_num = ?", phone_num).First(u).Error
}

func (u *User) FindUserByAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) FindUserByUpdate(db *gorm.DB, id int64) error {
	return db.Where("id = ?", id).Updates(u).Error
}
